import { defineStore } from 'pinia'
import MenuService from '@/api/service/MenuService'

const useMenuStore = defineStore({
  // 这里的id必须为唯一ID
  id: 'useMenuStore',
  state: (): ApiMenu.MenuData => {
    return {
      menu: []
    }
  },
  // 等同于vuex的getter
  getters: {},
  // pinia 放弃了 mutations 只使用 actions
  actions: {
    // actions可以用async做成异步形式
    async getMenu() {
      const _result = await MenuService.getUserMenu()
    }
  },
  // 持久化
  persist: {
    key: 'ai-painting-web-Meun',
    storage: window.sessionStorage
    // storage: window.localStorage
  }
})

export default useMenuStore
